/**
 * Created by CDog on 15/9/11.
 */

wcApp.factory('user', ['$http','$rootScope', function ($http,$rootScope) {


    var user_inner={};
    var flag=false;

    return {

        setUser: function (newUser) {
            user_inner = angular.copy(newUser);
        },

        unsetUser: function () {
            user_inner = {};
        },

        data: function () {
            return user_inner;
        },
        done: function () {
            return user_inner;
        },

        hasLogin: function () {
            if (user_inner._id) {
                return true;
            } else {
                $http.get($rootScope.baseUrl+'/users/getUser')
                    .success(function (resp, code) {
                        flag=true;
                        if (code == 200 && resp.code == 200 && resp.user.length != 0) {
                            user_inner = angular.copy(resp.user);
                            return  true
                        } else {
                            console.log(resp, code);
                            return false;
                        }

                    });
                return false;
            };
        }
    }

}]);